var app = getApp()
var util = require("../../utils/util.js")
var cardModel = require("../../model/cardModel.js")
var userUtil = require("../../utils/userUtil.js")
var tuiModel=require("../../model/tuiModel.js")
var wxParse = require('../../plugins/wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    card: {},
    tags:["详情","规格"],
    tagIndex:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var cusId = options.cusId
    var id = options.id
    var type = options.type
    if (cusId) { //通过分享邀请卡进入
      this.setData({
        cusId: cusId
      })
      //保存分享访问记录
      tuiModel.saveShare(id, type, cusId)
    }
    this.init(id, type)
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    
  },
  switchTag: function (e) {
    //console.log(e)
    this.setData({
      tagIndex: e.currentTarget.id
    })
  },
  init(id, type) {
    var data = {
      id: id,
      type: type
    }
    var that = this
    util.showLoading("加载中")
    cardModel.getCardInfo(data, res => {
      wx.hideLoading()
      if (res.status == 1) {
        util.failToast(res.msg)
        return
      }
      wxParse.wxParse('info', 'html', res.data.card.html, that, 5);
      that.setData({
        imgs: res.data.imgs,
        card: res.data.card,
        products:res.data.products
      })
    })
  },
  //支付页面
  navToPay() {
    if (!userUtil.isLogin()) {
      userUtil.toLogin()
      return
    }
    var card = this.data.card
    card.num = 1
    app.data.selectGoods = [card]
    var url = '../order_pay/order_pay'
    if (this.data.cusId)
      url += "?cusId=" + this.data.cusId
    wx.navigateTo({
      url: url
    })
  }
})